const {whitelist,varifyToken} = require('./utils/utils')
// whitelist 这个白名单用于控制哪些路由（或接口）可以绕过身份验证中间件而直接访问
const middleware = async (req,res,next)=>{
    if(whitelist.indexOf(req.url) != -1){
           let token = req.body.token
           if(!token) return res.err('token不能为空')
           let pass = await varifyToken(token)
           if(!pass) return res.err('token无效')
           req.user_info = pass
           next()
       }else{
        return next()
    }
}

module.exports = {
    middleware
};